package com.newasia.management.controller;

import com.newasia.commons.result.ResponseData;
import com.newasia.commons.result.ResponseUtil;
import com.newasia.management.ISysDealerService;
import com.newasia.management.constants.ManagementRetCode;
import com.newasia.management.dto.dealer.InvitedCodeRequest;
import com.newasia.management.dto.dealer.InvitedCodeResponse;
import com.newasia.management.shiro.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/management")
public class DealerController {

    @Reference(timeout = 3000)
    ISysDealerService sysDealerService;

    @GetMapping("/getInvitedCode")
    public ResponseData getInvitedCode(){
        Long userId = ShiroUtils.getUserInfo().getUserId();
        InvitedCodeRequest request = new InvitedCodeRequest();
        request.setUserId(userId);
        InvitedCodeResponse response = sysDealerService.getInvitedCode(request);
        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response);
        }
        return new ResponseUtil().setErrorMsg(response);
    }
}
